﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using YGWebMobileApi.Data;
using OneMile.DAL;
using OneMile.Common;
using OneMile.Entity.Model;
using System.Text;

namespace YGWebMobileApi.APIs
{
     [MobileAPI(Code = "MC0103", Name = "用户获取商家大图片")]
    public class UGetShopImgByShopId : BaseAPI, IProcessMessage
    {
        private DALUShops dalShop;
        protected DALUShops DalShop
        {
            get
            {
                if (dalShop == null)
                {
                    dalShop = DALFactory.getInstance().CreateUShopsDAL();
                }
                return dalShop;
            }
        }
        #region IProcessMessage 成员

        public MobileRspMsg ProcessMessage(MobileReqMsg reqMsg)
        {
            try
            {
                MobileRspMsg rspMsg = new MobileRspMsg(reqMsg);

                string ShopId = reqMsg.Body.GetFieldValue("ShopsId");
                bool useGZIP = reqMsg.Head.UseGZip;
                if (String.IsNullOrEmpty(ShopId))
                {
                    rspMsg.Head.RspCode = MessageCode.Paramter_Empty.Code;
                    rspMsg.Head.RspMsg = MessageCode.Paramter_Empty.Msg;
                    return rspMsg;
                }
                byte[] img = null;
                if (useGZIP)
                {
                    img = GZipUtils.Compress(DalShop.GetBigShopImgByShopId(ShopId));
                }
                else
                {
                    img = DalShop.GetBigShopImgByShopId(ShopId);
                }
                String imgString = MobileCryptoUtil.ToHexString(img);
                rspMsg.Body.AddField("ShopsImg", imgString);

                rspMsg.Head.RspCode = MessageCode.Success.Code;
                rspMsg.Head.RspMsg = MessageCode.Success.Msg;

                return rspMsg;
            }
            catch (Exception e)
            {
                ErrorLogWriter.Write("UGetShopImgByShopId()-" + e);
                throw e;
            }
        }

        #endregion
    }
}